<?php

/**
 * This is the model class for table "projects".
 *
 * The followings are the available columns in table 'projects':
 * @property integer $id
 * @property string $name
 * @property string $description
 * @property string $homepage
 * @property integer $is_public
 * @property integer $parent_id
 * @property string $created_on
 * @property string $updated_on
 * @property string $identifier
 * @property integer $status
 * @property integer $lft
 * @property integer $rgt
 *
 * The followings are the available model relations:
 * @property Boards[] $boards
 * @property CustomFieldsProjects[] $customFieldsProjects
 * @property Documents[] $documents
 * @property EnabledModules[] $enabledModules
 * @property Enumerations[] $enumerations
 * @property IssueCategories[] $issueCategories
 * @property Issues[] $issues
 * @property Members[] $members
 * @property News[] $news
 * @property Trackers[] $trackers
 * @property Queries[] $queries
 * @property Repositories[] $repositories
 * @property TimeEntries[] $timeEntries
 * @property Versions[] $versions
 * @property Wikis[] $wikises
 */
class Project extends CActiveRecord
{
    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Projects the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'projects';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('is_public, parent_id, status, lft, rgt', 'numerical', 'integerOnly'=>true),
            array('name, homepage, identifier', 'length', 'max'=>255),
            array('description, created_on, updated_on', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, name, description, homepage, is_public, parent_id, created_on, updated_on, identifier, status, lft, rgt', 'safe', 'on'=>'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'boards' => array(self::HAS_MANY, 'Board', 'project_id'),
            'customFieldsProjects' => array(self::HAS_MANY, 'CustomFieldsProject', 'project_id'),
            'documents' => array(self::HAS_MANY, 'Document', 'project_id'),
            'enabledModules' => array(self::HAS_MANY, 'EnabledModule', 'project_id'),
            'enumerations' => array(self::HAS_MANY, 'Enumeration', 'project_id'),
            'issueCategories' => array(self::HAS_MANY, 'IssueCategory', 'project_id'),
            'issues' => array(self::HAS_MANY, 'Issue', 'project_id'),
            'members' => array(self::HAS_MANY, 'Member', 'project_id'),
            'news' => array(self::HAS_MANY, 'News', 'project_id'),
            'trackers' => array(self::MANY_MANY, 'Tracker', 'projects_trackers(project_id, tracker_id)'),
            'queries' => array(self::HAS_MANY, 'Query', 'project_id'),
            'repositories' => array(self::HAS_MANY, 'Repository', 'project_id'),
            'timeEntries' => array(self::HAS_MANY, 'TimeEntry', 'project_id'),
            'versions' => array(self::HAS_MANY, 'Version', 'project_id'),
            'wikises' => array(self::HAS_MANY, 'Wiki', 'project_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'name' => 'Project',
            'description' => 'Description',
            'homepage' => 'Homepage',
            'is_public' => 'Public',
            'parent_id' => 'Parent',
            'created_on' => 'Created',
            'updated_on' => 'Updated',
            'identifier' => 'Identifier',
            'status' => 'Status',
            'lft' => 'Lft',
            'rgt' => 'Rgt',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id);
        $criteria->compare('name',$this->name,true);
        $criteria->compare('description',$this->description,true);
        $criteria->compare('homepage',$this->homepage,true);
        $criteria->compare('is_public',$this->is_public);
        $criteria->compare('parent_id',$this->parent_id);
        $criteria->compare('created_on',$this->created_on,true);
        $criteria->compare('updated_on',$this->updated_on,true);
        $criteria->compare('identifier',$this->identifier,true);
        $criteria->compare('status',$this->status);
        $criteria->compare('lft',$this->lft);
        $criteria->compare('rgt',$this->rgt);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
}